/*
 * Created on 2004-09-09
 */
package org.opencube.util.services.logging;

import java.io.IOException;

import org.apache.log4j.DailyRollingFileAppender;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.Priority;

/**
 * @author <a href="mailto:maciek@fingo.pl">Maciej Mroczko - FINGO</a>
 *
 * TODO comments
 */
@Deprecated
public class Logger
{
	private static org.apache.log4j.Logger logger = null;
	
	public static void init( String logPath, String loggingLevel )
	{
		try
		{
			DailyRollingFileAppender appender = new DailyRollingFileAppender( new PatternLayout( "%-5p %d{ISO8601} [%t] - %m%n" ), logPath, "'.'yyyy-MM-dd" );
			if( "ERROR".equalsIgnoreCase( loggingLevel ) )
			{
				appender.setThreshold( Priority.ERROR );
			}
			else if( "WARN".equalsIgnoreCase( loggingLevel ) )
			{
				appender.setThreshold( Priority.WARN );
			}
			else if( "INFO".equalsIgnoreCase( loggingLevel ) )
			{
				appender.setThreshold( Priority.INFO );
			}
			else
			{
				appender.setThreshold( Priority.DEBUG );
			}
			org.apache.log4j.Logger.getLogger( "org.opencube" ).addAppender( appender );
			logger = org.apache.log4j.Logger.getLogger( Logger.class );
		}
		catch( IOException e )
		{
			e.printStackTrace();
		}
	}
	
	public static void info( String message )
	{
		if( logger != null )
		{
			logger.info( message );
		}
	}
	
	public static void debug( String message )
	{
		if( logger != null )
		{
			logger.debug( message );
		}
	}
	
	public static void error( String message, Throwable exception )
	{
		if( logger != null )
		{
			logger.error( message, exception );
		}
	}
}
